//
//  ChosePositionViewController.m
//  u76ho
//
//  Created by m-air-01 on 16/1/10.
//  Copyright © 2016年 LV. All rights reserved.
//

#import "ChosePositionViewController.h"
#import "ChosePositionCell.h"
#import "PositionDetailViewController.h"
@interface ChosePositionViewController ()
<UITableViewDataSource,UITableViewDelegate>
{
    UITableView * _tabelView;
    NSMutableArray * dataSource;
    NSMutableArray * dataSource2;
}
@end

@implementation ChosePositionViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self main];
    self.navigationItem.title = @"选择职位";
    //[self addBackItem];
    //[self addNavgationBar];
    // Do any additional setup after loading the view.
}
-(void)main
{
    dataSource = [[NSMutableArray alloc]init];
    dataSource2 = [[NSMutableArray alloc]init];
    self.view.backgroundColor = [UIColor whiteColor];
    _tabelView = [[UITableView alloc]initWithFrame:CGRectMake(0, 64, SCREEN_WIDTH, SCREEN_HEIGHT-64) style:UITableViewStylePlain];
    _tabelView.delegate = self;
    _tabelView.dataSource = self;
    [_tabelView registerNib:[UINib nibWithNibName:@"ChosePositionCell" bundle:nil] forCellReuseIdentifier:@"ChosePositionCell"];
    [self.view addSubview:_tabelView];
    self.automaticallyAdjustsScrollViewInsets = NO;
    [self requestData];
}
-(void)requestData
{
    [U76HONet zhiweiListWithAction:@"" andDataBlock:^(ComplexPositionModel *model) {
        NSLog(@"职位分类获取数据成功了");
        [dataSource addObjectsFromArray:model.firstArray];
        [dataSource2 addObjectsFromArray:model.secondArray];
        [_tabelView reloadData];
    }];
    
}
#pragma mark - _tableViewDelegate
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return dataSource.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    ChosePositionCell * cell = [tableView dequeueReusableCellWithIdentifier:@"ChosePositionCell"];
    cell.firsModel = dataSource[indexPath.row];
    cell.arr = dataSource2[indexPath.row];
    return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 100;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    PositionDetailViewController * positionVC = [[PositionDetailViewController alloc]init];
    ComplexPositionDetailModel * model = [dataSource objectAtIndex:indexPath.row];
    positionVC.code = model.code;
    positionVC._typeid = @"0";
    positionVC.titles = model.typenames;
    [self.navigationController pushViewController:positionVC animated:YES];
}
#pragma  mark - 返回按钮图标
-(void)addBackItem{
    UIButton * backItem = [UIButton buttonWithType:UIButtonTypeCustom];
    backItem.frame = CGRectMake(0, 0, 9, 17);
    [backItem setImage:[UIImage imageNamed:@"返回图标"] forState:UIControlStateNormal];
    [backItem addTarget:self action:@selector(backItem:) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:backItem];
}
-(void)backItem:(id)sender
{
    [self.navigationController popViewControllerAnimated:YES];
}
#pragma mark - NAVgationBarTitle


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
